package com.example.demo.controller;

import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.QueryString;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.Student;
import com.example.demo.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController{


   @Autowired
   private StudentService studentService;

@GetMapping
public Result page(QueryString querystring){
    log.info("查询请求参数:{}",querystring);
    PageResult pageResult = studentService.page(querystring);
    return Result.success(pageResult);
}
@DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer>ids){
    log.info("删除请求参数:",ids);
    studentService.delete(ids);
    return Result.success();
}
@PostMapping
    public Result save(@RequestBody Student student){
    log.info("添加请求参数 student:",student);
    studentService.save(student);
    return Result.success();

}
@GetMapping("/{id}")
    public Result selectId(@PathVariable Integer id){
    log.info("添加请求参数："+id);
    Student s= studentService.selectId(id);
    return  Result.success(s);
}
@PutMapping
    public Result update(@RequestBody Student s){
    log.info("添加修改参数:"+s);
   studentService.update(s);
    return Result.success();
}
@PutMapping("/violation/{id}/{score}")
    public Result right(@PathVariable Integer id,@PathVariable Integer score){
    log.info("添加请求参数："+id,+score);
    studentService.right(id,score);
    return  Result.success();
}


}
